<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: absolute;
            top: 0;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: rgb(25, 225, 115);
            border-radius: 50%;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script type="module">
        import Myevent from './myevent.js';
        let myevent = new Myevent();
        let box = document.querySelector('.box');
        let count = 1;
        function move (box, target, dir) {

            let timer = setInterval(() => {
                let realX = parseInt(getComputedStyle(box)[dir]) ;
                console.log(realX);
                let step = 10 * (target >realX ? 1 : -1 );
                
                if (realX === target) {
                    clearInterval(timer);
                    // cb();
                    
                    myevent.trigger('myevent'+count);
                    count++;
                } else {
                    let endX = realX + step + 'px';
                    box.style[dir] = endX;
                }
            },100)
        }
        move(box, 300, 'left');
        myevent.addEvent('myevent1',function() {
            console.log('111');
            move(box,300,'top');
        })
        myevent.addEvent('myevent2',function() {
            console.log('222');
            move(box,0,'left');
        })
        myevent.addEvent('myevent3',function() {
            console.log('333');
            move(box,0,'top');
        })
        myevent.addEvent('myevent4',function() {
            console.log('444');
        })

        // move(box,300,'left',function() {
        //     move(box,300,'top',function(){
        //         move(box,0,'left',function(){
        //             move(box,0,'top',function(){
                        
        //             })
        //         })
        //     })
        // })
    </script>
</body>
</html>